import {createApp} from 'vue'
import App from './App.vue'
import ElementPlus from 'element-plus';
import 'element-plus/theme-chalk/index.css';
import locale from 'element-plus/lib/locale/lang/zh-cn';
import * as ElementPlusIconsVue from '@element-plus/icons-vue' /*引入图标*/
import router from "@/router";
import store from "@/store/index.js";
import {createPinia} from "pinia";
import axios from "axios";
import ImgCutter from 'vue-img-cutter'
// import API from "@/plugins/axiosInstance";

const pinia = createPinia()

const app = createApp(App)

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
    if (sessionStorage.getItem("token")) {
        config.headers.token = JSON.parse(sessionStorage.getItem("token"))
    }
    return config
})

// 添加响应拦截器
// axios.interceptors.response.use(function (response) {
//     console.log(JSON.stringify(response))
//     if (response.data.code == 200) {
//         return response
//     } else {
//         return false
//     }
// })

createApp(App).use(ImgCutter).use(pinia).use(store).use(router).use(ElementPlus, {locale}).mount("#app");

